﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};
	
	var authtypeData = Jxstar.findComboData('authtype');
	var paystatusData = Jxstar.findComboData('paystatus');
	var items = [{
		height: '97%',
		width: '97%',
		border: false,
		layout: 'form',
		style: 'padding:10px;',
		items: [{
			anchor:'100%',
			border: false,
			layout:'column',
			autoHeight:true,
			items:[{
				border:false,
				columnWidth:0.495,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'trigger', fieldLabel:'合同编号', name:'contract_pay__contract_code',
						anchor:'100%', readOnly:true, triggerClass:'x-form-search-trigger',
						maxLength:20, editable:true,
						onTriggerClick: function() {
							var selcfg = {pageType:'combogrid', nodeId:'contract_select', layoutPage:'', sourceField:'', targetField:'', whereSql:"", whereValue:'', whereType:'', isSame:'1', isShowData:'1', isMoreSelect:'0',isReadonly:'1',fieldName:'contract_pay.contract_code'};
							JxSelect.createSelectWin(selcfg, this, 'node_pay_plansub_form');
						}},
					{xtype:'textfield', fieldLabel:'合同名称', name:'contract_pay__contract_name', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'textfield', fieldLabel:'项目名称', name:'contract_pay__project_name', readOnly:true, anchor:'100%', maxLength:100},
					{xtype:'combo', fieldLabel:'授权方式', name:'contract_pay__auth_type',
						anchor:'100%', readOnly:true, editable:false,
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: authtypeData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: authtypeData[0][0]},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'合同金额(万元)', name:'contract_pay__contract_money', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'实施单位', name:'contract_pay__dept_name', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'textfield', fieldLabel:'收款单位', name:'contract_pay__provider_name', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'datefield', fieldLabel:'计划月份', name:'contract_pay__plan_month', format:'Y-m', anchor:'100%', readOnly:true},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'本月计划付款(万元)', name:'contract_pay__plan_money', defaultval:'0', anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'合同签约部门', name:'contract_pay__done_deptname', readOnly:true, anchor:'100%', maxLength:50},
					{xtype:'textfield', fieldLabel:'申请单号', name:'contract_pay__pay_code', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'hidden', fieldLabel:'申请人ID', name:'contract_pay__apply_userid', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'实施单位ID', name:'contract_pay__dept_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'收款单位ID', name:'contract_pay__provider_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'项目ID', name:'contract_pay__project_id', anchor:'100%'}
				]
			},{
				border:false,
				columnWidth:0.495,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'combo', fieldLabel:'付款计划状态', name:'contract_pay__plan_status', defaultval:'1',
						anchor:'100%', readOnly:true, editable:false,
						store: new Ext.data.SimpleStore({
							fields:['value','text'],
							data: paystatusData
						}),
						emptyText: jx.star.select,
						mode: 'local',
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text',
						value: paystatusData[0][0]},
					{xtype:'textfield', fieldLabel:'项目编码', name:'contract_pay__project_code', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'textfield', fieldLabel:'项目负责人', name:'contract_pay__project_user', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'立项批复金额(万元)', name:'contract_pay__project_money', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'已付款金额(万元)', name:'contract_pay__pay_money', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'numberfield', decimalPrecision:6, fieldLabel:'账面欠款(万元)', name:'contract_pay__last_money', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'numberfield', decimalPrecision:2, fieldLabel:'付款进度%（包含本次）', name:'contract_pay__pay_ratio', readOnly:true, anchor:'100%', maxLength:12},
					{xtype:'textfield', fieldLabel:'申请人', name:'contract_pay__apply_user', readOnly:true, anchor:'100%', maxLength:20},
					{xtype:'datefield', fieldLabel:'申请日期', name:'contract_pay__apply_date', format:'Y-m-d', anchor:'100%', readOnly:true},
					{xtype:'datefield', fieldLabel:'合同签订日期', name:'contract_pay__write_date', format:'Y-m-d', anchor:'100%', readOnly:true},
					{xtype:'hidden', fieldLabel:'合同签约部门ID', name:'contract_pay__done_deptid', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'合同ID', name:'contract_pay__contract_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'项目负责人ID', name:'contract_pay__project_userid', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'主键', name:'contract_pay__pay_id', anchor:'100%'},
					{xtype:'hidden', fieldLabel:'公司核准付款(万元)', name:'contract_pay__check_money', defaultval:'0', anchor:'100%'}
				]
			}
			]
		},{
			anchor:'100%',
			border: false,
			layout:'column',
			autoHeight:true,
			items:[{
				border:false,
				columnWidth:0.99,
				layout:'form',
				style: 'padding-left:10px;',
				items:[
					{xtype:'textarea', fieldLabel:'本次付款依据', name:'contract_pay__pay_cause', allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', width:'100%', height:48, maxLength:500}
				]
			}
			]
		}]
	}];
	
	config.param = {
		items: items,
		funid: 'pay_plansub'
	};

	config.initpage = function(formNode){
		var event = formNode.event;
		
		//扩展保存前事件，计划月份不能小于当前月份
		event.on('beforesave', function(event, data) {
			var form = event.form;
			var month = form.get('contract_pay__plan_month');
			
			//转换为1号
			month = Date.parseDate(month.format('Y-m')+'-01', 'Y-m-d');
			var curmonth = JxDefault.getCurMonth();
			if (curmonth > month) {
				JxHint.alert('计划月份不能小于当前月份！');
				return false;
			}
			
			var pay_money = form.getNum('contract_pay__pay_money');
			var plan_money = form.getNum('contract_pay__plan_money');
			var contract_money = form.getNum('contract_pay__contract_money');
			if (pay_money + plan_money > contract_money) {
				JxHint.alert('提示：加上当月计划，累计付款已经超过合同金额！');
			}
			
			return true;
		});
	};
	
	return new Jxstar.FormNode(config);
}